$(document).ready(function () {
    var typeId = getUrlParam("Rtype");
    $.ajax({
        url: "TongjiHandler.ashx?typeId=" + typeId,
        type: "GET",
        dataType: "json",
        success: function (data) {
            var typeArr = new Array();
            var numArr = new Array();
            $.each(data, function (i, n) {
                typeArr[i] = n["Name"];
                numArr[i] = n["Num"];
            })
            //alert(typeArr);
            //alert(numArr);
            //var arr=["诈骗电话","骚扰电话","对我进行人身攻击","推销假货","诈骗短信","传销","中介"]
            var myChart1 = echarts.init(document.getElementById('jbtype1'));
            var option = {
                tooltip: {//提示框
                    show: true
                },
                legend: {//图例
                    data: ['举报类型人数']
                },
                xAxis: [
                    {
                        type: 'value'
                    }
                ],
                yAxis: [{
                    type: 'category',
                    data: typeArr
                }],
                series: [//设置数据
                    {
                    itemStyle: {
                        normal: {
                            color: function (params) {
                                var colorList = ['#ff7241', '#ffd011', '#71cffe', '#40d041', '#aa7941',
                                        '#7170ff', '#d0a0ff'];
                                return colorList[params.dataIndex]
                            }
                        }
                    },
                    "name": "举报类型人数",
                    "type": "bar",
                    "data": numArr
                }
                ]
            };
            //为myCharts对象加载数据
            myChart1.setOption(option);
        }
    });
    $.ajax({
        url: "ashx/ReportTongJiTotalTypeHandler.ashx?typeId=1",
        type: "GET",
        dataType: "json",
        success: function (data) {
            //alert(data);
            var myChart2 = echarts.init(document.getElementById('jbMap'));
            option2 = {
                tooltip: {
                    tigger: 'item'
                },
                legend: {
                    orient: 'vertical', //布局方式
                    x: 'left', //水平安放位置
                    data: ['举报地区分布人数']
                },
                dataRange: {
                    min: 0,
                    max: 20000,
                    x: 'left',
                    y: 'bottom',
                    text: ['高', '低'],
                    calculable: true,
                    color: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee090', '#ffffbf', '#e0f3f8']
                },
                toolbox: {
                    show: true,
                    orient: 'vertical',
                    x: 'right',
                    y: 'center'
                },
                roamController: {
                    show: true,
                    x: 'right',
                    mapTypeControl: {
                        'china': true
                    }
                },
                series: [
                        {
                            name: '举报地区分布人数',
                            type: 'map',
                            mapType: 'china',
                            roam: false, //是否开启滚轮缩放和拖拽漫游
                            itemStyle: {
                                normal: {
                                    label: { show: true },
                                    borderWidth: 2,
                                    borderColor: '#ddd'
                                }, //默认样式
                                emphasis: { label: { show: true}}//强调样式
                            },
                            data: data
                        }
                    ]
            };
            //为myCharts对象加载数据
            myChart2.setOption(option2);
        }
    });

});

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
